package com.epoque.admin.server.rest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.epoque.admin.server.model.User;
import com.epoque.admin.server.service.UserService;
import com.epoque.common.msg.TableResultResponse;
import com.epoque.common.rest.BaseController;
import com.github.pagehelper.PageHelper;

import tk.mybatis.mapper.entity.Example;

/**
 * 
 * @ClassName: UserController
 * @Description: 用户控制类
 * @author qiuxianfeng
 * @date 2018年8月29日
 *
 */
@Controller
@RequestMapping("user")
public class UserController extends BaseController<UserService,User> {

	/**
	 * 
	 * @Title: page
	 * @author qiuxianfeng
	 * @Description: 分页查询用户信息
	 * @param @param limit
	 * @param @param offset
	 * @param @param name
	 * @param @return    参数
	 * @return TableResultResponse<User>    返回类型
	 * @throws
	 */
    @RequestMapping(value = "/page",method = RequestMethod.GET)
    @ResponseBody
    public TableResultResponse<User> page(@RequestParam(defaultValue = "10") int limit, @RequestParam(defaultValue = "1")int offset, String name){
        Example example = new Example(User.class);
        if(StringUtils.isNotBlank(name)) {
            example.createCriteria().andLike("name", "%" + name + "%");
            example.createCriteria().andLike("username", "%" + name + "%");
        }
        int count = baseBiz.selectCountByExample(example);
        PageHelper.startPage(offset, limit);
        return new TableResultResponse<User>(count,baseBiz.selectByExample(example));
    }


}
